{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 题目1：请使用Python中的循环，打印输出从1到100的所有奇数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "3\n",
      "5\n",
      "7\n",
      "9\n",
      "11\n",
      "13\n",
      "15\n",
      "17\n",
      "19\n",
      "21\n",
      "23\n",
      "25\n",
      "27\n",
      "29\n",
      "31\n",
      "33\n",
      "35\n",
      "37\n",
      "39\n",
      "41\n",
      "43\n",
      "45\n",
      "47\n",
      "49\n",
      "51\n",
      "53\n",
      "55\n",
      "57\n",
      "59\n",
      "61\n",
      "63\n",
      "65\n",
      "67\n",
      "69\n",
      "71\n",
      "73\n",
      "75\n",
      "77\n",
      "79\n",
      "81\n",
      "83\n",
      "85\n",
      "87\n",
      "89\n",
      "91\n",
      "93\n",
      "95\n",
      "97\n",
      "99\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,101):\n",
    "    if i % 2 == 1:\n",
    "        print (i)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 题目2：请将字符串 ”你好$$$我正在学Python@#@#现在需要&%&%&修改字符串” 中的符号变成一个空格，需要输出的格式为：”你好 我正在学Python 现在需要 修改字符串”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好 我正在学Python 现在需要 修改字符串\n"
     ]
    }
   ],
   "source": [
    "str1 = '你好$$$我正在学Python@#@#现在需要&%&%&修改字符串'\n",
    "str2 = str1.replace('$$$', ' ').replace('@#@#', ' ').replace('&%&%&', ' ')\n",
    "print (str2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好 我正在学Python 现在需要 修改字符串\n"
     ]
    }
   ],
   "source": [
    "import re\n",
    "str1 = '你好$$$我正在学Python@#@#现在需要&%&%&修改字符串'\n",
    "str2 = re.sub('[$@#&%]+', ' ' ,str1)\n",
    "print (str2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 题目3：输出 9*9 乘法口诀表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-01-04T12:18:17.953381Z",
     "start_time": "2019-01-04T12:18:17.938842Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1x1=1\t\n",
      "1x2=2\t2x2=4\t\n",
      "1x3=3\t2x3=6\t3x3=9\t\n",
      "1x4=4\t2x4=8\t3x4=12\t4x4=16\t\n",
      "1x5=5\t2x5=10\t3x5=15\t4x5=20\t5x5=25\t\n",
      "1x6=6\t2x6=12\t3x6=18\t4x6=24\t5x6=30\t6x6=36\t\n",
      "1x7=7\t2x7=14\t3x7=21\t4x7=28\t5x7=35\t6x7=42\t7x7=49\t\n",
      "1x8=8\t2x8=16\t3x8=24\t4x8=32\t5x8=40\t6x8=48\t7x8=56\t8x8=64\t\n",
      "1x9=9\t2x9=18\t3x9=27\t4x9=36\t5x9=45\t6x9=54\t7x9=63\t8x9=72\t9x9=81\t\n"
     ]
    }
   ],
   "source": [
    "for i in range(1, 10):\n",
    "    for j in range(1, i+1):\n",
    "        print (\"%dx%d=%d\\t\" % (j, i, i*j), end=\"\")\n",
    "    print(\"\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 题目4：请写出一个函数，当输入函数变量当月利润I，能返回应发放奖金总数，例如输出“利润100000元时，应发放奖金总数为10000元。”。\n",
    "其中，企业发放的奖金根据利润提成。利润(I)低于或等于10万元时，奖金可提10%；利润高于10万元，低于20万元时，低于10万元的部分按10%提成，高于10万元的部分，可提成7.5%；20万到40万之间时，高于20万元的部分，可提成5%；40万到60万之间时高于40万元的部分，可提成3%；60万到100万之间时，高于60万元的部分，可提成1.5%，高于100万元时，超过100万元的部分按1%提成"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-01-04T12:18:43.452862Z",
     "start_time": "2019-01-04T12:18:42.226135Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "净利润:2100000\n",
      "利润为2100000元时，应发奖金总数为50500元\n"
     ]
    }
   ],
   "source": [
    "def calcute_profit(I):\n",
    "    I = I / 10000\n",
    "    if I <= 10:\n",
    "        a = I * 0.1\n",
    "        return a * 10000\n",
    "    elif I <= 20 and I > 10:\n",
    "        b =0.25 + I * 0.075\n",
    "        return b * 10000\n",
    "    elif I <= 40 and I > 20:\n",
    "        c = 0.75 + I * 0.05\n",
    "        return c * 10000\n",
    "    elif I <= 60 and I > 40:\n",
    "        d = 1.55 + I * 0.03\n",
    "        return d * 10000\n",
    "    elif I <= 100 and I > 60:\n",
    "        e = 2.45 + I * 0.015\n",
    "        return e * 10000\n",
    "    else:\n",
    "        f = 2.95 + I * 0.01\n",
    "        return f * 10000\n",
    "    \n",
    "I = int(input('净利润:'))\n",
    "profit = calcute_profit(I)\n",
    "print ('利润为%d元时，应发奖金总数为%d元' % (I, profit))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-01-04T12:18:48.041910Z",
     "start_time": "2019-01-04T12:18:46.176321Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "净利润:2100000\n",
      "利润为2100000元时，应发奖金总数为50500元\n"
     ]
    }
   ],
   "source": [
    "def calcute_profit(I):\n",
    "    arr = [1000000,600000,400000,200000,100000,0] #这应该就是各个分界值了，把它们放在列表里方便访问\n",
    "    rat = [0.01,0.015,0.03,0.05,0.075,0.1] #这是各个分界值所对应的奖金比例值\n",
    "    r = 0                       #这是总奖金的初始值\n",
    "    for idx in range(0,6):      #有6个分界值当然要循环6次\n",
    "        if I > arr[idx]:\n",
    "            r = r + (I - arr[idx]) * rat[idx] \n",
    "            I = arr[idx]\n",
    "    return r\n",
    "\n",
    "I = int(input('净利润:'))\n",
    "profit = calcute_profit(I)\n",
    "print ('利润为%d元时，应发奖金总数为%d元' % (I, profit))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 题目5：用字典的值对字典进行排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[(0, 0), (2, 1), (1, 2), (4, 3), (3, 4)]\n"
     ]
    }
   ],
   "source": [
    "import operator\n",
    "x = {1: 2, 3: 4, 4:3, 2:1, 0:0}\n",
    "sorted_x = sorted(x.items(), key=operator.itemgetter(1))\n",
    "print (sorted_x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 题目6：请问一下两段代码的输出分别是什么？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "a = 1\n",
    "def fun(a):\n",
    "    a = 2\n",
    "fun(a)\n",
    "print (a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1]\n"
     ]
    }
   ],
   "source": [
    "a = []\n",
    "def fun(a):\n",
    "    a.append(1)\n",
    "fun(a)\n",
    "print (a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 题目7： 请问以下两段代码的输出分别是什么？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bbb\n",
      "aaa\n",
      "aaa\n"
     ]
    }
   ],
   "source": [
    "class Person:\n",
    "    name=\"aaa\"\n",
    "\n",
    "p1=Person()\n",
    "p2=Person()\n",
    "p1.name=\"bbb\"\n",
    "print (p1.name)\n",
    "print (p2.name)\n",
    "print (Person.name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1]\n",
      "[1]\n",
      "[1]\n"
     ]
    }
   ],
   "source": [
    "class Person:\n",
    "    name=[]\n",
    "\n",
    "p1=Person()\n",
    "p2=Person()\n",
    "p1.name.append(1)\n",
    "print (p1.name)\n",
    "print (p2.name)\n",
    "print (Person.name)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {
    "height": "153px",
    "width": "252px"
   },
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": "block",
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
